<?php

	session_start();

	// including
	include('../framework/functions.inc.php');

	// db onnect
	dbOpen();

	// if id is defined
	if (isset($_GET['id'])) {

		// get the current counter and access value
		$book = mysql_fetch_assoc(mysql_query("SELECT book_access, book_counter FROM book WHERE book_id = '".$_GET['id']."'"));

		// if book is loocked
		if ($book['book_access'] == '2' && !isset($_SESSION['user_id'])) {

			// display locked message
			header("Location: ../message.php?id=booklocked");
			exit;
		}
		else {

			// counter increment
			$book['book_counter']++;
			mysql_query("UPDATE book SET book_counter = '".$book['book_counter']."' WHERE book_id='".$_GET['id']."'");

			// go to preface page
			header("Location: content.php?id=".$_GET['id']."");
			exit;
		}
	}
	// display error mesage
	else
		header("Location: ../message.php?id=systemerror");
		
?>